#include "cpp_file/map_server.h"
namespace game {
static MapServer *server_instance_ = NULL;

MapServer::MapServer() {
}
MapServer::~MapServer() {
}

static inline void GetFileAndRead() {
  cout << "=================================================" << endl;
  string file_path = "data/UnitProto/1.txt";
  string file_data = "";
  char buffer[256];
  fstream out;
  out.open(file_path.c_str(), ios::in);
  while(!out.eof()) {
    out.getline(buffer, 256, '\n');
    file_data += buffer;
    file_data += '\n';
  }
  out.close();
  // cout << file_data << endl;
  UnitProto unit_proto;
  google::protobuf::TextFormat::ParseFromString(file_data, &unit_proto);
  cout << unit_proto.id() << endl;
  cout << unit_proto.name() <<endl;
}

void MapServer::TestFuncPointer(int a) {
  cout << a;
}

void MapServer::TestFuncPointer() {
  fp fptmp;
  fptmp = &MapServer::TestFuncPointer;
  for(int i = 0; i < 10; ++i) {
    (this->*fptmp)(i);
  }
  cout << endl;
}
void MapServer::Update() {
  // GetFileAndRead();
  TestFuncPointer();
  cout << "===================== end\n";
}

MapServer* MapServer::MapServerInstance() {
  std::cout << server_instance_;
  if (server_instance_ == NULL) {
    std::cout << "init server_instance\n";
    server_instance_ = new MapServer();
  }
  return server_instance_;
}
}

